const { formatResponse } = require("../utils/tool");
const {
  findAllBannerDao,
  updateBannerDao,
  createBannerDao,
  deleteBannerDao,
  findByPkBannerDao,
} = require("../dao/bannerDao");

const { ValidationError } = require("../utils/error");

exports.findAllBannerService = async () => {
  return await findAllBannerDao();
};

exports.updateBannerService = async (id, data) => {
  await updateBannerDao(id, data);
  return formatResponse(0, "", null);
};

exports.createBannerService = async (data) => {
  const res = await createBannerDao(data);
  return formatResponse(0, "", res.dataValues);
};

exports.deleteBannerService = async (id) => {
  const res = await deleteBannerDao(id);
  if (!res) throw new ValidationError("Banner is not exist");
  return formatResponse(0, "", null);
};

exports.findByIdBannerService = async (id) => {
  const res = await findByPkBannerDao(id);
  return formatResponse(0, "", res.dataValues);
};
